﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using RestaurantManagement.Controls;
using DevExpress.XtraBars.Docking2010.Views.WindowsUI;
using DevExpress.XtraBars.Docking2010.Views;

namespace RestaurantManagement
{
    public partial class frmMain : DevExpress.XtraEditors.XtraForm
    {
        object current;

        public frmMain()
        {
            InitializeComponent();
        }

        private void windowsUIView_QueryControl(object sender, DevExpress.XtraBars.Docking2010.Views.QueryControlEventArgs e)
        {
            BaseModule module = e.Document.Tag is BaseModule ? (BaseModule)e.Document.Tag :
                 Activator.CreateInstance(typeof(frmMain).Assembly.GetType(e.Document.ControlTypeName)) as BaseModule;
            module.InitModule(barManager, windowsUIView);
            BaseTile tile = null;
            if (windowsUIView.Tiles.TryGetValue(e.Document, out tile))
            {
                TileItemFrame frame = tile.CurrentFrame;
                object data = current ?? ((frame != null) ? frame.Tag : null);
                module.ShowModule(data);
            }
            e.Document.Tag = module;
            e.Control = module;
        }

        private void windowsUIView_TileClick(object sender, TileClickEventArgs e)
        {
            Tile tile = e.Tile as Tile;
            if (tile != null && tile.Document != null)
            {
                BaseModule module = tile.Document.Control as BaseModule;
                if (module != null)
                {
                    TileItemFrame frame = tile.CurrentFrame;
                    object data = (frame != null) ? frame.Tag : null;
                    module.ShowModule(data);
                }
                if (tile.Group == "Files")
                {
                    filesPageGroup.Parent = this.mainContainer;
                    mainContainer.ActivationTarget = filesPageGroup;
                }
                else if (tile.Group == "Systems")
                {
                    systemPageGroup.Parent = this.mainContainer;
                    mainContainer.ActivationTarget = systemPageGroup;
                }
                else if (tile.Group == "About")
                {
                    aboutPageGroup.Parent = this.mainContainer;
                    mainContainer.ActivationTarget = aboutPageGroup;
                }
                else if (tile.Group == "Category")
                {
                    accountingObjectCategory.Parent = this.mainContainer;
                    mainContainer.ActivationTarget = accountingObjectCategory;
                }
                else if (tile.Group == "Production")
                {
                    productionCategory.Parent = this.mainContainer;
                    mainContainer.ActivationTarget = productionCategory;
                }
                //if (tile.ActivationTarget == page)
                //{
                //    page.Document = tile.Document;
                //    page.Caption = tile.Elements[0].Text;
                //}
            }
        }
    }
}